

class Solution(object):
    def plusOne(self, digits):
        """
        :type digits: List[int]
        :rtype: List[int]
        """
        len_ = len(digits)
        a_ = digits.pop() + 1
        digits.append(a_)
        print(digits)
        for i in range(len_):
            position = len_ - i - 1
            print(position)
            new_ = digits[position]
            if new_ == 10:
                digits[position] = 0
                if position - 1 >= 0:
                    digits[position - 1] += 1
                else:
                    first = [1]
                    for b in digits:
                        first.append(b)
                    digits = first

        print(digits)


if __name__ == '__main__':
    sol = Solution()
    sol.plusOne([9, 9, 9, 9, 9, 9, 9])